﻿@model MVCBlog.Web.Models.Blog.IndexViewModel
@inject Microsoft.AspNetCore.Mvc.Localization.IViewLocalizer Localizer

@{
    ViewData["Title"] = Localizer["Blog"];
}
<h1>@ViewData["Title"]</h1>

@if (!string.IsNullOrEmpty(this.Model!.Tag) || !string.IsNullOrEmpty(this.Model.Search))
{
    <div class="card mt-3 mb-3">
        <div class="card-body">
            @if (!string.IsNullOrEmpty(this.Model.Tag))
            {
                <i class="fas fa-tag"></i>
                <text>@Localizer["Tag"]: @this.Model.Tag</text>
            }

            @if (!string.IsNullOrEmpty(this.Model.Tag) && !string.IsNullOrEmpty(this.Model.Search))
            {
                <br />
            }
            @if (!string.IsNullOrEmpty(this.Model.Search))
            {
                <i class="fas fa-search"></i>
                <text>@Localizer["Search:"] @this.Model.Search</text>
            }
        </div>
    </div>
}

<div class="row">
    <div class="col-md-12 col-lg-9">
        @if (this.Model.Entries.TotalNumberOfItems > 0)
        {
            foreach (var entry in this.Model.Entries)
            {
                <article class="mb-4">
                    <h2><a href="~/Blog/@entry.Url">@entry.Header</a></h2>
                    <partial name="_Header" model="@entry" />
                </article>
            }

            <pager paged-result="this.Model.Entries"></pager>
        }
        else
        {
            <p>@Localizer["No blog posts available"]</p>
        }
    </div>
    <div class="col-lg-3 d-none d-sm-none d-md-none d-lg-block">
        @if (Model.Tags.Count > 0)
        {
            <h3>@Localizer["Tags"]</h3>
            @foreach (var tag in Model.Tags)
            {
                <i class="fas fa-tag"></i> <a asp-controller="Blog" asp-action="Index" asp-route-tag="@tag.Name" class="text-nowrap">@tag.Name</a>
            }
        }

        <br />
        <br />
        @if (Model.PopularBlogEntries.Count > 0)
        {
            <h3>@Localizer["Popular posts"]</h3>
            @foreach (var entry in Model.PopularBlogEntries)
            {
                <a href="~/Blog/@entry.Url">@entry.Header</a>
                <br />
            }
        }
    </div>
</div>
